package androidx.legacy.app;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.BaseSavedState;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabWidget;
import java.util.ArrayList;

@Deprecated
public class FragmentTabHost extends TabHost implements OnTabChangeListener {
    private boolean ʻ;
    private d ʽ;
    private FrameLayout ˊ;
    private Context ˋ;
    private FragmentManager ˎ;
    private final ArrayList<d> ˏ = new ArrayList();
    private int ॱ;
    private OnTabChangeListener ॱॱ;

    static class SavedState extends BaseSavedState {
        public static final Creator<SavedState> CREATOR = new Creator<SavedState>() {
            public /* synthetic */ Object createFromParcel(Parcel parcel) {
                return ˏ(parcel);
            }

            public /* synthetic */ Object[] newArray(int i) {
                return ˊ(i);
            }

            public SavedState ˏ(Parcel parcel) {
                return new SavedState(parcel);
            }

            public SavedState[] ˊ(int i) {
                return new SavedState[i];
            }
        };
        String ˎ;

        SavedState(Parcelable parcelable) {
            super(parcelable);
        }

        SavedState(Parcel parcel) {
            super(parcel);
            this.ˎ = parcel.readString();
        }

        public void writeToParcel(Parcel parcel, int i) {
            super.writeToParcel(parcel, i);
            parcel.writeString(this.ˎ);
        }

        public String toString() {
            return "FragmentTabHost.SavedState{" + Integer.toHexString(System.identityHashCode(this)) + " curTab=" + this.ˎ + "}";
        }
    }

    static final class d {
        final Class<?> ˋ;
        final Bundle ˎ;
        Fragment ˏ;
        final String ॱ;
    }

    @Deprecated
    public FragmentTabHost(Context context) {
        super(context, null);
        ˋ(context, null);
    }

    @Deprecated
    public FragmentTabHost(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        ˋ(context, attributeSet);
    }

    private void ˋ(Context context, AttributeSet attributeSet) {
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, new int[]{16842995}, 0, 0);
        this.ॱ = obtainStyledAttributes.getResourceId(0, 0);
        obtainStyledAttributes.recycle();
        super.setOnTabChangedListener(this);
    }

    private void ˊ(Context context) {
        if (findViewById(16908307) == null) {
            View linearLayout = new LinearLayout(context);
            linearLayout.setOrientation(1);
            addView(linearLayout, new LayoutParams(-1, -1));
            View tabWidget = new TabWidget(context);
            tabWidget.setId(16908307);
            tabWidget.setOrientation(0);
            linearLayout.addView(tabWidget, new LinearLayout.LayoutParams(-1, -2, 0.0f));
            tabWidget = new FrameLayout(context);
            tabWidget.setId(16908305);
            linearLayout.addView(tabWidget, new LinearLayout.LayoutParams(0, 0, 0.0f));
            tabWidget = new FrameLayout(context);
            this.ˊ = tabWidget;
            this.ˊ.setId(this.ॱ);
            linearLayout.addView(tabWidget, new LinearLayout.LayoutParams(-1, 0, 1.0f));
        }
    }

    @Deprecated
    public void setup() {
        throw new IllegalStateException("Must call setup() that takes a Context and FragmentManager");
    }

    @Deprecated
    public void setup(Context context, FragmentManager fragmentManager) {
        ˊ(context);
        super.setup();
        this.ˋ = context;
        this.ˎ = fragmentManager;
        ˎ();
    }

    @Deprecated
    public void setup(Context context, FragmentManager fragmentManager, int i) {
        ˊ(context);
        super.setup();
        this.ˋ = context;
        this.ˎ = fragmentManager;
        this.ॱ = i;
        ˎ();
        this.ˊ.setId(i);
        if (getId() == -1) {
            setId(16908306);
        }
    }

    private void ˎ() {
        if (this.ˊ == null) {
            this.ˊ = (FrameLayout) findViewById(this.ॱ);
            if (this.ˊ == null) {
                throw new IllegalStateException("No tab content FrameLayout found for id " + this.ॱ);
            }
        }
    }

    @Deprecated
    public void setOnTabChangedListener(OnTabChangeListener onTabChangeListener) {
        this.ॱॱ = onTabChangeListener;
    }

    @Deprecated
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        String currentTabTag = getCurrentTabTag();
        FragmentTransaction fragmentTransaction = null;
        for (int i = 0; i < this.ˏ.size(); i++) {
            d dVar = (d) this.ˏ.get(i);
            dVar.ˏ = this.ˎ.findFragmentByTag(dVar.ॱ);
            if (!(dVar.ˏ == null || dVar.ˏ.isDetached())) {
                if (dVar.ॱ.equals(currentTabTag)) {
                    this.ʽ = dVar;
                } else {
                    if (fragmentTransaction == null) {
                        fragmentTransaction = this.ˎ.beginTransaction();
                    }
                    fragmentTransaction.detach(dVar.ˏ);
                }
            }
        }
        this.ʻ = true;
        FragmentTransaction ॱ = ॱ(currentTabTag, fragmentTransaction);
        if (ॱ != null) {
            ॱ.commit();
            this.ˎ.executePendingTransactions();
        }
    }

    @Deprecated
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        this.ʻ = false;
    }

    @Deprecated
    protected Parcelable onSaveInstanceState() {
        Parcelable savedState = new SavedState(super.onSaveInstanceState());
        savedState.ˎ = getCurrentTabTag();
        return savedState;
    }

    @Deprecated
    protected void onRestoreInstanceState(Parcelable parcelable) {
        if (parcelable instanceof SavedState) {
            SavedState savedState = (SavedState) parcelable;
            super.onRestoreInstanceState(savedState.getSuperState());
            setCurrentTabByTag(savedState.ˎ);
            return;
        }
        super.onRestoreInstanceState(parcelable);
    }

    @Deprecated
    public void onTabChanged(String str) {
        if (this.ʻ) {
            FragmentTransaction ॱ = ॱ(str, null);
            if (ॱ != null) {
                ॱ.commit();
            }
        }
        if (this.ॱॱ != null) {
            this.ॱॱ.onTabChanged(str);
        }
    }

    private FragmentTransaction ॱ(String str, FragmentTransaction fragmentTransaction) {
        d dVar = null;
        int i = 0;
        while (i < this.ˏ.size()) {
            d dVar2 = (d) this.ˏ.get(i);
            if (!dVar2.ॱ.equals(str)) {
                dVar2 = dVar;
            }
            i++;
            dVar = dVar2;
        }
        if (dVar == null) {
            throw new IllegalStateException("No tab known for tag " + str);
        }
        if (this.ʽ != dVar) {
            if (fragmentTransaction == null) {
                fragmentTransaction = this.ˎ.beginTransaction();
            }
            if (!(this.ʽ == null || this.ʽ.ˏ == null)) {
                fragmentTransaction.detach(this.ʽ.ˏ);
            }
            if (dVar != null) {
                if (dVar.ˏ == null) {
                    dVar.ˏ = Fragment.instantiate(this.ˋ, dVar.ˋ.getName(), dVar.ˎ);
                    fragmentTransaction.add(this.ॱ, dVar.ˏ, dVar.ॱ);
                } else {
                    fragmentTransaction.attach(dVar.ˏ);
                }
            }
            this.ʽ = dVar;
        }
        return fragmentTransaction;
    }
}
